<?php
/**
 * comfiger
 * 2016-01-21
 **/
namespace Xijie\Model;
use Think\Model;
class CostlogModel extends Model {
	//定义表名称
	protected $tableName = 'costorder';
	
	/**
	 * 获取费用总数
	 **/
	public function getCostLogListCount($where=array()){
		return $this->alias('orders')->where($where)->count();
	}
	
	/**
	 * 获取列表
	 **/
	public function getCostLogList($page, $where=array(), $orderby='roomnumber asc, order_id asc'){
		return $this->alias('orders')
					->join('left join momoda_member as member on orders.contract = member.contract')
					->field('DISTINCT orders.*, member.btime, member.etime')
					->where($where)
					->page($page, C('PAGE_SIZE'))
					->order($orderby)
					->select();
	}
	
	/**
	 * 获取所有数据，不分页处理
	 **/
	public function getCostLogAllList($where=array(), $orderby='roomnumber asc, order_id asc'){
		return $this->alias('orders')
					->join('left join momoda_member as member on orders.contract = member.contract')
					->field('DISTINCT orders.*, member.btime, member.etime')
					->where($where)
					->order($orderby)
					->select();
	}

	/**
	 * 获取列表
	 **/
	public function getCostLogInfo($where=array()){
		return $this->where($where)->order('order_id asc')->select();
	}
	
	/**
	 * 设置费用状态
	 **/
	public function editCostLogInfo($where=array(), $setField=array()){
		return $this->where($where)->setField($setField);
	}
	
	/**
	 * 添加一条费用明细
	 */
	public function addCostInfo($data){
		return $this->add($data);
	}
	
	/**
	 * 批量添加数据
	 **/
	public function addCostInfoAll($data){
		return $this->addAll($data);
	}
	
	/**
	 * 根据账单ID获取账单详情
	 **/
	public function getCostInfoByWhere($where){
		return $this->where($where)->find();
	}
	
	public function getCostAllListByWhere($where){
		return $this->where($where)->order('order_id desc')->select();
	}

	/**
	 * 删除账单
	 **/
	public function deleteCostInfo($where){
		return $this->where($where)->delete();
	}
	
}

